%h3.page_title
  Group: #{@group.name}

%br
%table.zebra-striped
  %thead
    %tr
      %th Group
      %th
  %tr
    %td
      %b
        Name:
    %td
      = @group.name
      &nbsp;
      = link_to edit_admin_group_path(@group), class: "btn btn-small pull-right" do
        %i.icon-edit
        Edit
  %tr
    %td
      %b
        Description:
    %td
      = @group.description
  %tr
    %td
      %b
        Path:
    %td
      %span.monospace= File.join(Gitlab.config.gitlab_shell.repos_path, @group.path)
  %tr
    %td
      %b
        Owner:
    %td
      = @group.owner_name
      .pull-right
        = link_to "#", class: "btn btn-small change-owner-link" do
          %i.icon-edit
          Change owner

  %tr.change-owner-holder.hide
    %td.bgred
      %b.cred
        New Owner:
    %td.bgred
      = form_for [:admin, @group] do |f|
        = f.select :owner_id, User.all.map { |user| [user.name, user.id] }, {}, {class: 'chosen'}
        %div
          = f.submit 'Change Owner', class: "btn btn-remove"
          = link_to "Cancel", "#", class: "btn change-owner-cancel-link"

- if @group.projects.any?
  %fieldset
    %legend Projects (#{@group.projects.count})
    %table
      %thead
        %tr
          %th Project name
          %th Path
          %th Users
          %th.cred Danger Zone!
      - @group.projects.each do |project|
        %tr
          %td
            = link_to project.name_with_namespace, [:admin, project]
          %td
            %span.monospace= project.path_with_namespace + ".git"
          %td= project.users.count
          %td.bgred
            = link_to 'Transfer project to global namespace', remove_project_admin_group_path(@group, project_id: project.id), confirm: 'Remove project from group and move to global namespace. Are you sure?', method: :delete, class: "btn btn-remove small"

  = form_tag project_teams_update_admin_group_path(@group), id: "new_team_member", class: "bulk_import", method: :put  do
    %table.zebra-striped
      %thead
        %tr
          %th Users
          %th Project Access:

      - @group.users.each do |user|
        - next unless user
        %tr{class: "user_#{user.id}"}
          %td.name= link_to user.name, admin_user_path(user)
          %td.projects_access
            - user.authorized_projects.in_namespace(@group).each do |project|
              - u_p = user.users_projects.in_project(project).first
              - next unless u_p
              %span
                = project.name_with_namespace
                = link_to "(#{ u_p.project_access_human })", edit_admin_project_member_path(project, user)
      %tr
        %td.input= select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), multiple: true, data: {placeholder: 'Select users'}, class: 'chosen span5'
        %td= select_tag :project_access, options_for_select(Project.access_options), {class: "project-access-select chosen span3"}

      %tr
        %td= submit_tag 'Add user to projects in group', class: "btn btn-create"
        %td
          Read more about project permissions
          %strong= link_to "here", help_permissions_path, class: "vlink"

- else
  %fieldset
    %legend Group is empty

= form_tag project_update_admin_group_path(@group), class: "bulk_import", method: :put  do
  %fieldset
    %legend Move projects to group
    .alert
      You can move only projects with existing repos
      %br
      Group projects will be moved in group directory and will not be accessible by old path
    .clearfix
      = label_tag :project_ids do
        Projects
      .input
        = select_tag :project_ids, options_from_collection_for_select(@projects , :id, :name_with_namespace), multiple: true, data: {placeholder: 'Select projects'}, class: 'chosen span5'
    .form-actions
      = submit_tag 'Move projects', class: "btn btn-create"

